import {Command} from '../constant';
import Taro from '@tarojs/taro';
import {Dispatch} from 'typings';
import {IAllReducerProps} from '../types';
import {getReducerData} from '@/redux/store';
import {extraPathsValue} from '@/redux/util';
import api from 'api';

export default (dispatch: Dispatch) => {
  let action = {
    commonChange(...param: any) {
      dispatch({
        type: Command.commonChange,
        payload: extraPathsValue(...arguments),
      });
    },
    async page() {},
    /**
     * 初始化
     */
    async query() {},

    // 活动物业公告列表
    async getProperty(params) {
      let {pageNum, propertyNoticeList} = getData().main;
      action.commonChange('main.isLoading', true);
      let res = await api.pagesIndexController.getNoticeList(params);
      if (res.code == '200') {
        if (pageNum == 1) {
          action.commonChange('main.propertyNoticeList', res.data.rows);
          action.commonChange('main.totalPages', res.data.total);
        } else {
          let newList = propertyNoticeList.concat(res.data.rows);
          action.commonChange('main.propertyNoticeList', newList);
          action.commonChange('main.totalPages', res.data.total);
        }
      }
      action.commonChange('main.isLoading', false);
    },
  };
  return action;
};

function getData(): IAllReducerProps {
  return {
    main: getReducerData('packageANoticeMain'),
  };
}

//create by moon https://github.com/creasy2010/moon
